﻿using FluentNHibernate.Mapping;
using PAP.Domain.Core.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NHibernate;
using FluentNHibernate.Utils.Reflection;
using FluentNHibernate;
using PAP.Domain.Core.ValueObjects;

namespace PAP.Infrastructure.DataAccess.NH.Mappings
{
    public abstract class EntityMap<TKey,TEntity> : ClassMap<TEntity>
        where TEntity : Entity<TKey>
    {
        public EntityMap()
        {
            Id(x => x.Id, "Id");

            Map(Reveal.Member<TEntity>("_entityState"), "EntityState")
                .CustomType<EntityState>()
                .Not.Nullable();

            Version(Reveal.Member<TEntity>("_version"))
                .Column("EntityVersion")
                .Generated.Always()
                .CustomType<long>()
                .Not.Nullable();
        }
    }
}
